package Items.Top01.Lease;

import java.util.Scanner;

public class Manager {
    Scanner in=new Scanner(System.in);
    private int pos = 0;//记录车辆数量
    Car[] cars = new Car[20];

    public int getPos() {
        return pos;
    }

    public void setPos(int pos) {
        this.pos = pos;
    }

    public Manager() {
        cars[0] = new LittleCar("京NY28588", "宝马X6    ", 800, "轿车", false, 4);
        cars[1] = new LittleCar("京CNY3284", "宝马550i  ", 600, "轿车", true, 4);
        cars[2] = new LittleCar("京NT37465", "别克林荫大道", 300, "轿车", true, 4);
        cars[3] = new LittleCar("京NT96968", "别克GL8   ", 600, "轿车", false, 4);

        cars[4] = new PassengerCar("京6566754", "金杯   ", 800, 16, false, "大客");
        cars[5] = new PassengerCar("京8696997", "金龙   ", 800, 16, true, "大客");
        cars[6] = new PassengerCar("京9696996", "金杯   ", 1500, 34, false, "大客");
        cars[7] = new PassengerCar("京8696998", "金龙   ", 1500, 34, true, "大客");
        pos = 8;
    }

    public void showCarList() {//显示车辆信息

        for (int i = 0; i < cars.length; i++) {
            if (cars[i] == null)
                continue;
            System.out.println(cars[i].toString());
        }
        System.out.println("当前正常使用车辆"+getPos());
    }

    public Car lease(String cartype,String carNum,int days){//租借
//        for (int i = 0; i < getPos(); i++) {
//            if (cars[i].isState()) {
//                continue;
//            }
//            if (cars[i].getModel().equals(carType))
//                System.out.println(cars[i]);
//        }
        for (int i=0;i<getPos();i++){
            if (cars[i].getCarNum().equals(carNum)){
                System.out.println("租借成功");
                System.out.println("价格为"+cars[i].countRent(days));
                cars[i].setState(true);
                return cars[i];
            }else if (!cars[i].getCarNum().equals(carNum)){
                break;
            }
        }
        return null;
    }

    public boolean add(Car car){//添加
        /*for (;;){
            System.out.println("请选择");
            String model=in.next();
            if (model.equals("大客")){
                cars[pos]=new PassengerCar(carnum,brand,price,seat,false,"大客");
                pos++;
                System.out.println("已添加采购车辆信息");
                return;
            }else if (model.equals("轿车")){
                cars[pos]=new LittleCar(carnum,brand,price,"轿车",false,seat);
                pos++;
                System.out.println("已添加采购车辆信息");
                return;
            }
        }*/
        cars[pos++]=car;
        return true;
    }

    public boolean delCar(String carnum){
        showCarList();
        for (int i=0;i<pos;i++){
            if (cars[i].getCarNum().equals(carnum)){
                cars[i]=null;
                for (int j=i;j<pos;j++){
                    cars[j]=cars[j+1];
                    cars[pos-1]=null;
                }
                pos--;
                return true;
            }

        }
        return false;
    }

    public void returnCar(String carnum){
        for (int i=0;i<pos;i++){
            if (cars[i].getCarNum().equals(carnum)){
                cars[i].setState(false);
                System.out.println("还车成功");
                return;
            }
        }
        System.out.println("还车失败，请检查所输入牌照是否正确");
    }
    }


